package com.javafamily.controller;

import com.javafamily.bean.Pets;
import com.javafamily.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pets")
public class PetsController {

    @Autowired
    private PetService petService;

    @PostMapping("/savepets")
    public boolean saveHandler(@RequestBody Pets pets) {
        return petService.savePets(pets);
    }

    @DeleteMapping("/delpets/{id}")
    public boolean deleteHandler(@PathVariable("id") int id) {
        return petService.removePetsById(id);
    }

    @PutMapping("/updatepets")
    public boolean updateHandler(@RequestBody Pets pets) {
        return petService.modifyPets(pets);
    }


    @GetMapping("/getpets/{id}")
    public Pets getByIdHandler(@PathVariable("id") int id) {
        return petService.getPetsById(id);
    }

    @GetMapping("/listpets")
    public List<Pets> listHandler() {
        return petService.listAllPets();
    }

    @GetMapping("/getPetsByIdOrName")
    public List<Pets> getByNameHandler(@RequestBody Pets pets) {
        return petService.findPetsByIdOrName(pets);
    }

}
